

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 以往记录 Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…  Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示">
<meta property="og:url" content="http://example.com/2022/02/09/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%BA%94%EF%BC%89%E4%BD%BF%E7%94%A8base64%E7%BC%96%E7%A0%81%E5%AE%9E%E7%8E%B0%E5%A4%B4%E5%83%8F%E4%BF%AE%E6%94%B9%20_%20%E7%94%A8%E6%88%B7%E4%B8%AA%E4%BA%BA%E4%BF%A1%E6%81%AF%E4%BF%AE%E6%94%B9%20_%20JQuery%E5%8A%A8%E6%80%81%E6%8F%90%E7%A4%BA/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 以往记录 Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…  Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d3b5fd87e64e4777a2180510da8aa0a7.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/702114e51e7c412eb51bba141cf13911.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d6e90b8e53164244a96ed5d08f0f0ebe.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/1e0387b8f2174e77a9ae1a55c65d5f11.png">
<meta property="article:published_time" content="2022-02-09T12:38:42.000Z">
<meta property="article:modified_time" content="2022-08-22T15:51:01.049Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v2.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/d3b5fd87e64e4777a2180510da8aa0a7.png">
  
  
  
  <title>Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-02-09 20:38" pubdate>
          2022年2月9日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          9.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          80 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="以往记录"><a href="#以往记录" class="headerlink" title="以往记录"></a>以往记录</h1><ul>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122722369">Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122726356">Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接口</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122743352">Web项目实战 | 购物系统v2.0 | 开发记录（三）分页显示 | 根据商品名称进行模糊查询</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122773805">Web项目实战 | 购物系统v2.0 | 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 | 使用省市区三级联动 | 使用JQuery 插件实现图片上传</a></p>
</li>
</ul>
<h1 id="一、运行环境"><a href="#一、运行环境" class="headerlink" title="一、运行环境"></a>一、运行环境</h1><hr>
<ul>
<li>windows10</li>
<li>IDEA 2021.1 专业版</li>
<li>JDK8</li>
<li>SpringBoot2</li>
<li>Druid 1.2.5</li>
<li>Bootstrap 4.6.0</li>
<li>MySQL 8</li>
<li>Navicat 11</li>
</ul>
<h1 id="二、实现头像修改"><a href="#二、实现头像修改" class="headerlink" title="二、实现头像修改"></a>二、实现头像修改</h1><hr>
<p>JS头像修改部分可参考 <a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122773805">点击查看</a></p>
<p>笔者使用现成的JQuery插件实现图片修改，该插件将可裁剪图片，并将裁剪的图片转化为base64编码进行显示，故可将字符串形式的base64编码直接保存的数据库，节省空间<br><img src="https://img-blog.csdnimg.cn/d3b5fd87e64e4777a2180510da8aa0a7.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/702114e51e7c412eb51bba141cf13911.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>JS代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">//裁剪后的处理</span><br>$(<span class="hljs-string">&quot;#sureCut&quot;</span>).<span class="hljs-title function_">on</span>(<span class="hljs-string">&quot;click&quot;</span>,<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">if</span> ($(<span class="hljs-string">&quot;#tailoringImg&quot;</span>).<span class="hljs-title function_">attr</span>(<span class="hljs-string">&quot;src&quot;</span>) == <span class="hljs-literal">null</span> )&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>    &#125;<span class="hljs-keyword">else</span>&#123;<br>        <span class="hljs-keyword">var</span> cas = $(<span class="hljs-string">&#x27;#tailoringImg&#x27;</span>).<span class="hljs-title function_">cropper</span>(<span class="hljs-string">&#x27;getCroppedCanvas&#x27;</span>);<span class="hljs-comment">//获取被裁剪后的canvas</span><br>        <span class="hljs-keyword">var</span> base64url = cas.<span class="hljs-title function_">toDataURL</span>(<span class="hljs-string">&#x27;image/png&#x27;</span>); <span class="hljs-comment">//转换为base64地址形式</span><br>        $(<span class="hljs-string">&quot;#finalImg&quot;</span>).<span class="hljs-title function_">prop</span>(<span class="hljs-string">&quot;src&quot;</span>,base64url);<span class="hljs-comment">//显示为图片的形式</span><br>        $.<span class="hljs-title function_">ajax</span>(&#123;<br>            <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/user/info.html&#x27;</span>,<br>            <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;PUT&#x27;</span>,<br>            <span class="hljs-attr">data</span>: &#123;<span class="hljs-attr">base64url</span>:base64url&#125;,<br>            <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span>&#123; <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;修改头像请求失败.&#x27;</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>);&#125;,<br>            <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> &#123;<span class="hljs-title function_">alert</span>(data); location.<span class="hljs-title function_">reload</span>()&#125;<br>        &#125;)<br>        <span class="hljs-comment">//关闭裁剪框</span><br>        <span class="hljs-title function_">closeTailor</span>();<br>    &#125;<br>&#125;);<br></code></pre></td></tr></table></figure>
<p>控制层代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PutMapping(&quot;/user/info.html&quot;)</span><br><span class="hljs-meta">@ResponseBody</span><br><span class="hljs-keyword">public</span> String <span class="hljs-title function_">modifyUserImg</span><span class="hljs-params">(String base64url, HttpSession session)</span>&#123;<br>    <span class="hljs-type">int</span> <span class="hljs-variable">length</span> <span class="hljs-operator">=</span> base64url.length();<br>    <span class="hljs-comment">// 限制图片文件的大小.</span><br>    <span class="hljs-keyword">if</span>(length / <span class="hljs-number">4</span> / <span class="hljs-number">1024</span> / <span class="hljs-number">1024</span> * <span class="hljs-number">3</span> &gt; <span class="hljs-number">2</span> || length &gt; <span class="hljs-number">16777215</span>) <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;文件过大&quot;</span>;<br>    <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> (User) session.getAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>);<br>    user.setUserImgSrc(base64url);<br>    <span class="hljs-keyword">return</span> userService.autoModifyUserById(user) == <span class="hljs-number">1</span> ? <span class="hljs-string">&quot;修改成功!&quot;</span> : <span class="hljs-string">&quot;修改失败.&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="三、用户个人信息修改"><a href="#三、用户个人信息修改" class="headerlink" title="三、用户个人信息修改"></a>三、用户个人信息修改</h1><hr>
<p><img src="https://img-blog.csdnimg.cn/d6e90b8e53164244a96ed5d08f0f0ebe.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>在提交表单的时候需要注意，有的信息是没有在表单里的（密码修改暂时不写在这里）比如最关键的就是用户ID，当前也可以从session里获取当前的用户信息，不过这里直接写到表单里，方便之后实现批量用户管理。</p>
<p>除了这一点之外，还有其他的字段需要特殊处理的，比如 <code>birthday</code>生日字段，在MySQL数据表里存储的为<code>Date</code>格式，为了更好的显示生日信息，笔者在实体类里添加了birthday_format变量，专门用户前端的显示，同时也用于在保存信息时，转化为Date格式的一个依据。</p>
<p>故在后端进行保存信息时，还需要对这种字段特殊处理。</p>
<p>前端页面：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-user-modify&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;id&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.id&#125;&quot;</span> <span class="hljs-attr">hidden</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userCode&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userCode&#125;&quot;</span> <span class="hljs-attr">hidden</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userPassword&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userPassword&#125;&quot;</span> <span class="hljs-attr">hidden</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userRole&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userRole&#125;&quot;</span> <span class="hljs-attr">hidden</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container-fluid row&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-5&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;finalImg&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 100px;height: 100px;border-radius: 50%;&quot;</span></span><br><span class="hljs-tag">                        <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userImgSrc&#125;&quot;</span> <span class="hljs-attr">th:data-src</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userImgSrc&#125;&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;replaceImg&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-danger u-btn-modify-img&quot;</span>&gt;</span>编辑头像<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><br>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-7&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>身份:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-danger&quot;</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;session.userRole.roleName&#125;&quot;</span>/&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span><br>                        性别:<br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;gender&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-gender-man&quot;</span>  <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;2&quot;</span> <span class="hljs-attr">th:data-gender</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.gender&#125;&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;p-0&quot;</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-gender-man&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;background: none&quot;</span>&gt;</span><br>                        男<br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;gender&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-gender-woman&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span> <span class="hljs-attr">th:data-gender</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.gender&#125;&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;p-0&quot;</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-gender-woman&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;background: none&quot;</span>&gt;</span><br>                        女<br>                    <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-birthday&quot;</span>&gt;</span>生日:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;birthday_format&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;date&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-birthday&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.birthday_format&#125;&quot;</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>名称:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-name&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userName&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userName&#125;&quot;</span> <span class="hljs-attr">th:data-name</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.userName&#125;&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;color: gray; font-size: 10px&quot;</span>&gt;</span>* 目前只支持中文，最大长度5<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-phone&quot;</span>&gt;</span>联系电话:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;phone&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-phone&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.phone&#125;&quot;</span>/&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;color: gray; font-size: 10px&quot;</span>&gt;</span>* 暂时只支持11位电话<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-province&quot;</span>&gt;</span>地区:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userProvince&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-province&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userProvince&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userCity&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userCity&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userArea&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userArea&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;form-address&quot;</span>&gt;</span>详细地址:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userAddress&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-address&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userAddress&#125;&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;详细地址&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;color: gray; font-size: 10px&quot;</span>&gt;</span>* 限制在128个字符以内<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-center&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;u-btn-modify-save&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary&quot;</span>&gt;</span>保存信息<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>JS代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">// 检验</span><br><span class="hljs-keyword">var</span> check_phone = <span class="hljs-literal">false</span><br><span class="hljs-keyword">var</span> check_name = <span class="hljs-literal">false</span><br><span class="hljs-keyword">var</span> check_address = <span class="hljs-literal">false</span><br>$(<span class="hljs-string">&#x27;#form-phone&#x27;</span>).<span class="hljs-title function_">bind</span>(<span class="hljs-string">&#x27;input propertychange blur&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">let</span> reg = <span class="hljs-regexp">/^1\d&#123;10&#125;$/</span><br>    <span class="hljs-keyword">if</span>(reg.<span class="hljs-title function_">test</span>($(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">val</span>()))&#123;<br>        check_phone = <span class="hljs-literal">true</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;green&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;√&quot;</span>)<br><br>    &#125; <span class="hljs-keyword">else</span>&#123;<br>        check_phone = <span class="hljs-literal">false</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;red&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;* 请输入规范的联系电话&quot;</span>)<br>    &#125;<br>&#125;);<br>$(<span class="hljs-string">&#x27;#form-name&#x27;</span>).<span class="hljs-title function_">bind</span>(<span class="hljs-string">&#x27;input propertychange blur&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">let</span> reg = <span class="hljs-regexp">/^[\u4E00-\u9FA5]+$/</span><br>    <span class="hljs-keyword">if</span>(reg.<span class="hljs-title function_">test</span>($(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">val</span>()) &amp;&amp; $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">val</span>().<span class="hljs-property">length</span> &lt;= <span class="hljs-number">5</span>)&#123;<br>        check_name = <span class="hljs-literal">true</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;green&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;√&quot;</span>)<br><br>    &#125; <span class="hljs-keyword">else</span>&#123;<br>        check_name = <span class="hljs-literal">false</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;red&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;* 请输入规范的中文名称&quot;</span>)<br>    &#125;<br>&#125;)<br>$(<span class="hljs-string">&#x27;#form-address&#x27;</span>).<span class="hljs-title function_">bind</span>(<span class="hljs-string">&#x27;input propertychange blur&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">if</span>($(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">val</span>().<span class="hljs-property">length</span> &lt;= <span class="hljs-number">128</span>)&#123;<br>        check_address = <span class="hljs-literal">true</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;green&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;目前长度: &quot;</span>+ $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">val</span>().<span class="hljs-property">length</span> + <span class="hljs-string">&quot; √&quot;</span>)<br><br>    &#125; <span class="hljs-keyword">else</span>&#123;<br>        check_address = <span class="hljs-literal">false</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;color&#x27;</span>, <span class="hljs-string">&#x27;red&#x27;</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">next</span>().<span class="hljs-title function_">text</span>(<span class="hljs-string">&quot;* 请输入指定范围内的详细地址&quot;</span>)<br>    &#125;<br>&#125;)<br><span class="hljs-comment">// 保存信息</span><br>$(<span class="hljs-string">&#x27;#u-btn-modify-save&#x27;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br><br>    $(<span class="hljs-string">&#x27;#form-name&#x27;</span>).<span class="hljs-title function_">blur</span>();<br>    $(<span class="hljs-string">&#x27;#form-phone&#x27;</span>).<span class="hljs-title function_">blur</span>();<br>    $(<span class="hljs-string">&#x27;#form-address&#x27;</span>).<span class="hljs-title function_">blur</span>();<br><br>    <span class="hljs-keyword">if</span>(check_name &amp;&amp; check_phone &amp;&amp; check_address)&#123;<br>        $.<span class="hljs-title function_">ajax</span>(&#123;<br>            <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/user/info.html&#x27;</span>,<br>            <span class="hljs-attr">data</span>: $(<span class="hljs-string">&#x27;#form-user-modify&#x27;</span>).<span class="hljs-title function_">serialize</span>(),<br>            <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>            <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> &#123;<br>                <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;保存信息请求失败.&#x27;</span>);<br>                <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>)<br>            &#125;,<br>            <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span>&#123;<br>                <span class="hljs-title function_">alert</span>(data)<br>                location.<span class="hljs-title function_">reload</span>()<br>            &#125;<br>        &#125;)<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;请按提示输入规范的信息.&#x27;</span>)<br>&#125;)<br></code></pre></td></tr></table></figure>

<p>控制层代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PostMapping(&quot;/user/info.html&quot;)</span><br><span class="hljs-meta">@ResponseBody</span><br><span class="hljs-keyword">public</span> String <span class="hljs-title function_">modifyUserInfo</span><span class="hljs-params">(User user,</span><br><span class="hljs-params">                              <span class="hljs-meta">@RequestParam(&quot;userProvince&quot;)</span> String userProvince,</span><br><span class="hljs-params">                              <span class="hljs-meta">@RequestParam(&quot;userCity&quot;)</span> String userCity,</span><br><span class="hljs-params">                              <span class="hljs-meta">@RequestParam(&quot;userArea&quot;)</span> String userArea,</span><br><span class="hljs-params">                              <span class="hljs-meta">@RequestParam(&quot;userAddress&quot;)</span> String userAddress,</span><br><span class="hljs-params">                              HttpSession session)</span> &#123;<br>    <span class="hljs-comment">// 有些信息没有存在于表单，先获取原先的用户信息</span><br>    <span class="hljs-type">User</span> <span class="hljs-variable">userInfo</span> <span class="hljs-operator">=</span> (User) session.getAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>);<br>    user.setUserImgSrc(userInfo.getUserImgSrc());<br>    <span class="hljs-comment">// 特殊处理的字段</span><br>    <span class="hljs-keyword">try</span> &#123;<br>        user.setBirthday(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>(String.valueOf(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SimpleDateFormat</span>(<span class="hljs-string">&quot;yyyy-MM-dd&quot;</span>).parse(user.getBirthday_format()))));<br>    &#125; <span class="hljs-keyword">catch</span> (ParseException e) &#123;<br>        e.printStackTrace();<br>    &#125;<br>    user.setAddress(String.join(<span class="hljs-string">&quot;-&quot;</span>, userProvince, userCity, userArea, userAddress));<br>    user.setModifyBy(userInfo.getId());<br>    user.setModifyDate(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>());<br>    <span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> userService.autoModifyUserById(user);<br>    <span class="hljs-keyword">if</span>(i == <span class="hljs-number">1</span>) &#123;<br>        session.setAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>, user);<br>    &#125;<br>    <span class="hljs-keyword">return</span>  i == <span class="hljs-number">1</span> ? <span class="hljs-string">&quot;修改成功!&quot;</span> : <span class="hljs-string">&quot;修改失败.&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>
<h1 id="四、Bug-amp-DeBug"><a href="#四、Bug-amp-DeBug" class="headerlink" title="四、Bug &amp; DeBug"></a>四、Bug &amp; DeBug</h1><hr>
<p><strong>问题1：</strong> 在设计用户信息修改模块时，无法正确显示用户的生日信息</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;birthday&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;date&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;form-birthday&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;session.userInfo.birthday&#125;&quot;</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>SQL表中<code>birthday</code>字段的类型 <code>date</code></p>
<p>pojo类bitrhday变量的类型为 <code>java.util.Date;</code><br>serializeArray</p>
<p><strong>解决1：</strong> 在User实体类中添加一个变量<code> birthday_format</code> ，表示规格化后的日期，类型为String专门用于输出，然后添加相应的get、set方法，接着修改原先<code>birthday</code>变量的set方法，在里面添加对<code>bitrhday_format</code>变量的赋值。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setBirthday</span><span class="hljs-params">(Date birthday)</span> &#123;<br>    <span class="hljs-built_in">this</span>.birthday = birthday;<br>    setBirthday_format(<span class="hljs-keyword">new</span> <span class="hljs-title class_">SimpleDateFormat</span>(<span class="hljs-string">&quot;yyyy-MM-dd&quot;</span>).format(birthday));<br>&#125;<br></code></pre></td></tr></table></figure>
<p>修改后，前端的birthday改成birthday_format即可</p>
<p><strong>问题2：</strong> 在保存头像图片时，找不到正确的路径</p>
<p><img src="https://img-blog.csdnimg.cn/1e0387b8f2174e77a9ae1a55c65d5f11.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p><strong>解决2：</strong> transferTo方法执行时，会默认在前面添加一个web的路径，则需先获取工件的类路径作为保存位置的前缀，但直接保存图片文件会比较耗空间，之后修改为base64编码字符串的形式存储图片，将编码直接存储到数据库就行了，不用保存到服务端的工件。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-built_in">this</span>.getClass().getResource(<span class="hljs-string">&quot;/&quot;</span>).getPath().replaceFirst(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-string">&quot;&quot;</span>)<br></code></pre></td></tr></table></figure>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/" class="category-chain-item">项目实战:购物系统v2.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/">#项目实战:购物系统v2.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示</div>
      <div>http://example.com/2022/02/09/Web项目实战 _ 购物系统v2.0 _ 开发记录（五）使用base64编码实现头像修改 _ 用户个人信息修改 _ JQuery动态提示/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年2月9日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/12/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%B8%83%EF%BC%89SpringBoot%E6%95%B4%E5%90%88Shiro%E6%A1%86%E6%9E%B6%E8%BF%9B%E8%A1%8C%E8%BA%AB%E4%BB%BD%E8%AE%A4%E8%AF%81%20_%20Shiro%20%E5%8A%A0%E7%9B%90(MD5+Salt)%E9%AA%8C%E8%AF%81%E7%99%BB%E9%99%86%20_%20%E6%95%B0%E6%8D%AE%E8%A1%A8%E7%BB%93%E6%9E%84%E4%BC%98%E5%8C%96%E9%81%BF%E5%85%8D%E5%A4%96%E9%94%AE+%E8%AE%BE%E7%BD%AE%E4%B8%AD%E9%97%B4%E8%A1%A8/" title="Web项目实战 _ 购物系统v2.0 _ 开发记录（七）SpringBoot整合Shiro框架进行身份认证 _ Shiro 加盐(MD5+Salt)验证登陆 _ 数据表结构优化避免外键+设置中间表">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v2.0 _ 开发记录（七）SpringBoot整合Shiro框架进行身份认证 _ Shiro 加盐(MD5+Salt)验证登陆 _ 数据表结构优化避免外键+设置中间表</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/08/Shiro%20%E7%AC%94%E8%AE%B01%20Shrio%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84%20MDK5%20+%20salt%20%E5%8A%A0%E5%AF%86%E6%A1%88%E4%BE%8B%20SpringBoot%E6%95%B4%E5%90%88Shiro+SSM+Thymeleaf%E6%A1%88%E4%BE%8B/" title="Shiro 笔记1 Shrio体系结构 MDK5 + salt 加密案例 SpringBoot整合Shiro+SSM+Thymeleaf案例">
                        <span class="hidden-mobile">Shiro 笔记1 Shrio体系结构 MDK5 + salt 加密案例 SpringBoot整合Shiro+SSM+Thymeleaf案例</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
